package com.ruoyi;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class test {
    private static Map<String, String> yingshe = new HashMap<String, String>() {{
        put("vin","车架号");
        put("bts_timestamp","信号时间");
        put("pt_d","信号日期");
        put("w_time","入库时间");
        put("MDC_Rdr0WarnSectionDst","1号超声波雷达测距(以前车标右侧第一颗雷达为起始，顺时针方向)");
        put("MDC_Rdr1WarnSectionDst","2号超声波雷达测距");
        put("MDC_Rdr2WarnSectionDst","3号超声波雷达测距");
        put("MDC_Rdr3WarnSectionDst","4号超声波雷达测距");
        put("MDC_Rdr4WarnSectionDst","5号超声波雷达测距");
        put("MDC_Rdr5WarnSectionDst","6号超声波雷达测距");
        put("MDC_Rdr6WarnSectionDst","7号超声波雷达测距");
        put("MDC_Rdr7WarnSectionDst","8号超声波雷达测距");
        put("MDC_Rdr8WarnSectionDst","9号超声波雷达测距");
        put("MDC_Rdr9WarnSectionDst","10号超声波雷达测距");
        put("MDC_Rdr10WarnSectionDst","11号超声波雷达测距");
        put("MDC_Rdr11WarnSectionDst","12号超声波雷达测距");
        put("VDC_ActGearSt","档位");
        put("ABM_CrashSt_915","碰撞信号触发时间");
        put("VIU_HzrdLampFctSt","危险报警闪光灯");
        put("LCU_FLTurnLampOnSt","左转向灯");
        put("LCU_FRTurnLampOnSt","右转向灯");
        put("TRM_BrkLampFctSts_962","倒车灯");
        put("VIU_RvsLampFctSts","刹车灯");
        put("VIU_LoBeamFctSt","近光灯");
        put("VIU_HiBeamFctSt","远光灯");
        put("IPB_VehicleSpeed","整车车速(ESP车速)");
        put("ABM_IMU_LongAcceleration","纵向加速度");
        put("ABM_IMU_LateralAcceleration","横向加速度");
        put("ADS_INS_accZ","垂向加速度");
        put("ADS_INS_pitch","俯仰角速度");
        put("ADS_INS_roll","横滚角速度");
        put("ABM_IMU_YawRate","横摆角速度");
        put("IPB_PushRodActTrvl","制动推杆行程");
        put("IPB_APB_MasCylBrakeP","制动主缸压力");
        put("EPS_SteerWheelAngle","车轮转角");
        put("MCUF_ActRotSpd","驱动电机转速");
        put("MCUR_ActRotSpd","驱动电机转速");
        put("MCUF_ActTq","驱动电机扭矩");
        put("MCUR_ActTq","驱动电机扭矩");
        put("ADS_NicaFctSta","智驾功能状态数据(开启、退出、抑制(横纵向干预)和就绪信号)NCA开启状态");
        put("ADS_ParkStMac","智能泊车辅助(APA)");
        put("ADS_AVPFctSta","代客泊车辅助(AVP)");
        put("ADS_AccFunctionStatus","自适应巡航辅助(ACC)");
        put("ADS_LKAWarn","车道保持辅助(LKA)");
        put("ADS_BSDLeWarn","盲区监测预警(BSD)-左");
        put("ADS_BSDRiWarn","盲区监测预警(BSD)-右");
        put("ADS_FCWWarn","前向碰撞预警(FCW)");
        put("ADS_AEBAxCtrlReq","自动紧急制动(AEB)");
        put("ADS_RCTALeWarn","后向横穿碰撞预警(RCTA)");
        put("ADS_RCTARiWarn","后向横穿碰撞预警(RCTA)");
        put("ADS_RCTBLeWarn","后向横穿碰撞制动(RCTB)");
        put("ADS_RCTBRiWarn","后向横穿碰撞制动(RCTB)");
        put("ADS_FCTALeWarn","前向横穿碰撞预警(FCTA)");
        put("ADS_FCTARiWarn","前向横穿碰撞预警(FCTA)");
        put("ADS_FCTBLeWarn","前向横穿碰撞制动(FCTB)");
        put("ADS_FCTBRiWarn","前向横穿碰撞制动(FCTB)");
        put("ADS_RCWWarn","后向碰撞预警(RCW)");
        put("ADS_LDWWarn","车道偏离预警(LDW)");
        put("ADS_NicaRmnLEDVisual","人工接管预警提示");
        put("ADS_NicaRmnAcoustic","");
        put("ADS_TakeoverLvl","");
        put("ADS_TakeoverID","");
        put("ADS_TakeoverExtd1","");
        put("ADS_TakeoverExtd2","");
        put("ADS_SteerAgCtrlEnaReq","方向盘转角指令");
        put("ADS_SteerAgReq","方向盘转角指令");
        put("ADS_DrvTarTqEna","纵向控制指令");
        put("ADS_DrvTarTq","");
        put("ADS_BrkTarTqEna","");
        put("ADS_BrkTarTq","");
        put("ADS_PwrOnOffReq","远程启动状态");
        put("VDC_DriverSeatOccptSt","驾驶员在位");
        put("VDC_PassSeatOccptSt","副驾坐人状态");
        put("VIU_PassSeatBltSt","副驾安全带状态");
        put("VIU_PassDoorSt_688","副驾侧门开关状态");
        put("VIU_DrvrDoorSt_688","驾驶侧门开关状态");
        put("VDC_BrkPedalPressed","制动踏板开启关闭状态");
        put("ADS_HODRmn","HOD数值");
        put("EPS_SteeringAngle_272","方向盘转角");
        put("EPS_TorsionBarTorque","方向盘操作扭矩");
        put("VDC_AccPedalPosition","油门踏板开度(加速踏板行程值)");
        put("ADS_RadarWarnSection0Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection1Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection2Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection3Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection4Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection5Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection6Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection7Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection8Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection9Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection10Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection11Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection12Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection13Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection14Distance","雷达告警扇区与障碍物距离");
        put("ADS_RadarWarnSection15Distance","雷达告警扇区与障碍物距离");
        put("VCU_Gear","档位");
        put("ABM_CrashOutputStatus","碰撞信号触发时间");
        put("BCM_HazardLightSts","危险报警闪光灯");
        put("BCM_LeftTurnFunctionSt","左转向灯");
        put("BCM_RightTurnFunctionSt","右转向灯");
        put("BCM_brakeLightSts","刹车灯");
        put("BCM_LowBeamStatus","近光灯");
        put("BCM_HighBeamStatus","远光灯");
        put("ESP_VehicleSpeed","整车车速(ESP车速)");
        put("ESP_LongAcceleration","纵向加速度");
        put("ESP_LateralAcceleration","横向加速度");
        put("ESP_YawRate","横摆角速度");
        put("iB_sOutputRodAct","制动推杆行程");
        put("esc_PlungerPressure","制动主缸压力");
        put("eps_sasSteeringAngle","车轮转角");
        put("MCUF0_speed","驱动电机转速");
        put("MCUR0_speed","驱动电机转速");
        put("MCUF0_torqueEst","驱动电机扭矩");
        put("MCUR0_torqueEst","驱动电机扭矩");
        put("ADS_NicaFunctionStatus","智驾功能状态数据(开启、退出、抑制(横纵向干预)和就绪信号)NCA开启状态");
        put("ADS_AvpFunctionStatus","代客泊车辅助(AVP)");
        put("ADS_LKAWarning","车道保持辅助(LKA)");
        put("ADS_LeftMirrWarningCmd","盲区监测预警(BSD)");
        put("ADS_RightMirrWarningCmd","盲区监测预警(BSD)");
        put("ADS_FcwWaning","前向碰撞预警(FCW)");
        put("ADS_AebWaning","自动紧急制动(AEB)");
        put("ADS_RctaLeftWarning","后向横穿碰撞预警(RCTA)");
        put("ADS_RctaRightWarning","后向横穿碰撞预警(RCTA)");
        put("ADS_RctbLeftWarning","后向横穿碰撞制动(RCTB)");
        put("ADS_RctbRightWarning","后向横穿碰撞制动(RCTB)");
        put("ADS_FctaLeftWarning","前向横穿碰撞预警(FCTA)");
        put("ADS_FctaRightWarning","前向横穿碰撞预警(FCTA)");
        put("ADS_FctbLeftWarning","前向横穿碰撞制动(FCTB)");
        put("ADS_FctbRightWarning","前向横穿碰撞制动(FCTB)");
        put("ADS_RcwWarning","后向碰撞预警(RCW)");
        put("ADS_LdwWarning","车道偏离预警(LDW)");
        put("ADS_TakeoverLevel","人工接管预警提示");
        put("ADS_TORIDCorrespErrorID","");
        put("ADS_TakeoverExtended1","");
        put("ADS_TakeoverExtended2","");
        put("apa_epsSterAngTarValReq","方向盘转角指令");
        put("mrr_accTargetAx","纵向控制指令");
        put("mrr_aebTargetAx","纵向控制指令");
        put("APA_LaebTargetAx","纵向控制指令");
        put("BLE_ReqtPolicyInfo","智能手机发送的刹车指令");
        put("bcm_driverSeatDetectSts","驾驶员在位");
        put("ic_passengerSeatDetectSts","副驾坐人状态");
        put("IC_PassengerSeatBeltStatus","副驾安全带状态");
        put("BCM_PassengerDoorStatus","副驾侧门开关状态");
        put("BCM_DriverDoorStatus","驾驶侧门开关状态");
        put("VCU_brakePedalState","制动踏板开启关闭状态");
        put("VCU_accelPos","制动踏板开度(制动踏板行程值)");
        put("VCU_AccPedalPosition","油门踏板开度(加速踏板行程值)");
        put("acu_crashOutputStatus","碰撞信号触发时间");
        put("bcm_hazardLightSwSts","危险报警闪光灯");
        put("bcm_lowBeamSts","近光灯");
        put("bcm_highBeamSts","远光灯");
        put("esc_vehicleSpeed_530","整车车速(ESP车速)");
        put("esc_longAcceleration","纵向加速度");
        put("esc_lateralAcceleration","横向加速度");
        put("esc_yawRate","横摆角速度");
        put("esc_masCylBrakePressure","制动主缸压力");
        put("eps_sasSteeringAngleSpd","车轮转角");
        put("mrr_accTargetAx_537","自动紧急制动(AEB)");
        put("ADS_PwrOnOffReq_522","远程启动状态");
        put("IC_driverSeatBeltStatus","主驾安全带状态");
        put("bcm_doorFLSts","副驾侧门开关状态");
        put("bcm_doorFRSts","驾驶侧门开关状态");
        put("vcu_brakePedalPressed","制动踏板开启关闭状态");
        put("HOD_SensorGain","HOD数值");
        put("eps_sasSteeringAngle_324","方向盘转角");
        put("ESP_VehicleSpeed_504","整车车速(ESP车速)");
        put("MCUF0_speed_275","驱动电机转速");
        put("MCUR0_speed_274","驱动电机转速");
        put("MCUF0_torqueEst_259","驱动电机扭矩");
        put("MCUR0_torqueEst_258","驱动电机扭矩");
        put("mrr_accTargetAx_432","纵向控制指令");
        put("VCU_brakePedalState_273","制动踏板开启关闭状态");
        put("EPS_TorsionBarTorque_376","方向盘操作扭矩");
        put("TRM_BrkLampFctSts","倒车灯");
        put("acu_crashOutputStatus_896","碰撞信号触发时间");
        put("bcm_hazardLightSwSts_673","危险报警闪光灯");
        put("esc_longAcceleration_594","纵向加速度");
        put("esc_lateralAcceleration_594","横向加速度");
        put("esc_yawRate_594","横摆角速度");
        put("iB_sOutputRodAct_453","制动推杆行程");
        put("esc_masCylBrakePressure_530","制动主缸压力");
        put("ADS_ParkStMac_940","智能泊车辅助(APA)");
        put("apa_epsSterAngTarValReq_602","方向盘转角指令");
        put("bcm_driverSeatDetectSts_673","驾驶员在位");
        put("ic_passengerSeatDetectSts_754","副驾坐人状态");
        put("bcm_doorFLSts_673","副驾侧门开关状态");
        put("bcm_doorFRSts_673","驾驶侧门开关状态");
        put("eps_torsionBarTorque_292","方向盘操作扭矩");
        put("vcu_accPedalPosition_577","油门踏板开度(加速踏板行程值)");
    }};
    public static void main(String[] args) {
        String inputPath = "D:/csv"; //现有csv文件路径
        String outputPath = "D:/newcsv";    //输出的新csv文件存放地址

        try {
            Files.createDirectories(Paths.get(outputPath));

            File[] files = new File(inputPath).listFiles((dir, name) ->
                    name.toLowerCase().endsWith(".csv"));

            if (files == null || files.length == 0) {
                System.out.println("未找到CSV文件");
                return;
            }

            for (File file : files) {
                List<String> lines = Files.readAllLines(file.toPath());
                if (!lines.isEmpty()) {
                    String[] header=lines.get(0).split(",");
                    lines.add(1, String.join(",",getNewValues(header)));
                    Path output = Paths.get(outputPath, file.getName());
                    Files.write(output, lines);
                }
            }

            System.out.println("处理完成！输出目录: " + outputPath);
        } catch (IOException e) {
            System.err.println("处理失败: " + e.getMessage());
        }
    }

    private static String[] getNewValues(String[] keys){
        String[] result = new String[keys.length];
        for (int i = 0; i < keys.length; i++) {
            result[i] = yingshe.get(keys[i]) !=null ? yingshe.get(keys[i]) : keys[i];
        }
        return result;
    }
}
